package net.atos.spring.services;

import static com.google.common.collect.Lists.newArrayList;

import java.util.List;

import net.atos.spring.domain.Book;

import org.springframework.stereotype.Service;

@Service
public class BookService {

    public List<Book> getAllBooks() {
	return ALL_BOOKS;
    }

    public void removeBook(int index) {
	ALL_BOOKS.remove(index);
    }

    public int countBooks() {
	return ALL_BOOKS.size();
    }

    public void addBook(String title, String author) {
	final Book book = new Book(title, author);
	ALL_BOOKS.add(book);
    }

    public void addBook(Book book) {
	ALL_BOOKS.add(book);
    }

    public void updateBook(Book book, Integer index) {
	ALL_BOOKS.set(index, book);
    }

    public Book getById(int index) {
	return ALL_BOOKS.get(index);
    }

    private static final List<Book> ALL_BOOKS = newArrayList
	    (
		    new Book("Lord of the Rings", "Tolkien"),
		    new Book("Hobbit", "Tolkien"),
		    new Book("Silmarillion", "Tolkien")
	    );
}
